/* ReservationColl.java
 * 
 * This Collection class holds Reservations
 * 
 * 
 * Greg Warner
 * Derek Dupuis
 * Michael Dixey
 * Alex Schwartz
 */


import java.util.*;

public class ReservationColl extends TreeMap< String, Reservation >
   implements CollectionIF<Reservation>
{
   
   /*collection class constructor*/
   public ReservationColl()
   {
      super();
   }
   
   //-------------CollectionIF methods--------
   //adds a reservation to the collection
   public boolean add( Reservation r )
   {
      if( ! this.containsKey(r.travelerName() ) )
      {
         this.put(r.travelerName(),r);
         return true;
      }
      else
      {
         return false;
      }
   }
   
   
   /* "FIND" method -
    * searches the collection for a 
    * reservation stored under the given
    * string "s", returns true if found
    * false if not found.
    */
   public boolean find( String s )
   {
      return this.containsKey(s);
   }
   
   /* "GET" method -
    * returns the reservation stored 
    * under the given string
    */
   public Reservation get(String s )
   {
      return super.get( s );
   }
   
   /* toString for Collection of Reservations
    * provides a clean printout of all reservations 
    * within the collection. sets up formatting and 
    * calls the toString for eachreservation within 
    * the collection
    */
   public String toString()
   {
      String s = "RESERVATIONS:\n";
      Set t = this.keySet();
      Iterator iter = t.iterator();
      while( iter.hasNext() )
      {
         s = s + this.get( iter.next() ).toString();
      }
      return s;
   }
   
}
